﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BUS;

namespace WindowsFormsApplication1
{
    public partial class frmDangNhap : Form
    {
        public frmDangNhap()
        {
            InitializeComponent();
        }

        private void btnDangNhap_Click(object sender, EventArgs e)
        {
            DangNhapBUS DN_BUS = new DangNhapBUS();
            bool KQ;
            if (comboBox1.SelectedIndex == 0)
            {
                KQ = false;
                DN_BUS.Kieuketnoi(KQ);
                if (DN_BUS.Ket_quaKN2() == true)
                {
                    MessageBox.Show("thanh cong");
                    if (MessageBox.Show("dang nhap thanh cong", "thong bao", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation) == DialogResult.OK)
                    {
                        frmNhanVien f = new frmNhanVien();
                        f.Show();
                    }
                }
                else
                {
                    MessageBox.Show("dang nhap that bai");
                }
            }
        
           // if(comboBox1.SelectedIndex== 1)
            else 
            {
                KQ = true;
              DN_BUS.Kieuketnoi(KQ);
              if (DN_BUS.KetQua_KetNoi(txtsever.Text, txtdatabase.Text, txtuser.Text, txtpass.Text) == true)
                {
                    if (MessageBox.Show("Đăng Nhập Hệ Thống Thành Công", "Thông Báo", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.Yes)
                    {
                        Form1 f = new Form1();
                        f.Show();
                    }
                }
              else
                {
                    MessageBox.Show("dang nhap that bai");
                }

            }
        }
        private void btnThoat_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

            if (comboBox1.SelectedIndex==0)
            {
                
               
                txtuser.Enabled = false;
                txtuser.ForeColor = Color.Blue;
                txtpass.Enabled  = false;
                txtpass.ForeColor = Color.Blue;
                txtdatabase.Enabled = false;
                txtdatabase.ForeColor = Color.Brown;
               
            }
            if(comboBox1.SelectedIndex==1)
            {

                txtuser.Enabled = true;
                txtpass.Enabled= true;
                txtuser.ForeColor = Color.Yellow;
                txtpass.ForeColor = Color.Yellow;
            
            }
        }

        private void frmDangNhap_Load(object sender, EventArgs e)
        {

        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            
            //Properties.Settings.De= txtsever.Text;
            //Properties.Settings.Default.txtuser = txtuser.Text;
            //comboBox1.SelectedIndex = 0;
            //Properties.Settings.Default.txtdatabase = txtdatabase.Text;
            //Properties.Settings.Default.txtpass = txtpass.Text;
        }

        private void frmDangNhap_Load_1(object sender, EventArgs e)
        {
            
        }
    }
}
